/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ResultWindow.java
 *
 * Created on Apr 23, 2011, 11:10:02 PM
 */

package view;

import graph.DijkstraResult;
import java.awt.event.ActionListener;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import models.ResultTableModel;

/**
 *
 * @author borysfan
 */
public class ResultWindow extends javax.swing.JFrame {

    /** Creates new form ResultWindow */
    public ResultWindow() {
        initComponents();
   
       
      
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        DetailsBtn = new javax.swing.JButton();
        CancelBtn = new javax.swing.JButton();
        save = new javax.swing.JButton();
        infoPath = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new ResultTableModel()
        );
        jScrollPane1.setViewportView(jTable1);

        DetailsBtn.setText("Szczegóły");

        CancelBtn.setText("Anuluj");

        save.setText("Zapisz");

        infoPath.setText("info");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(DetailsBtn)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 341, Short.MAX_VALUE)
                                .addComponent(save)
                                .addGap(18, 18, 18)
                                .addComponent(CancelBtn)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(infoPath, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
                        .addGap(117, 117, 117))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(infoPath)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DetailsBtn)
                    .addComponent(CancelBtn)
                    .addComponent(save))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CancelBtn;
    private javax.swing.JButton DetailsBtn;
    private javax.swing.JLabel infoPath;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton save;
    // End of variables declaration//GEN-END:variables

    public void setTableModel(ResultTableModel tableModel) {
        jTable1.setModel(tableModel);
    }

    public void setDetailsBtn(ActionListener listener) {
        DetailsBtn.addActionListener(listener);
    }

    public void setSaveBtnAction(ActionListener listener) {
        save.addActionListener(listener);
    }

    public void setCancelBtnAction(ActionListener listener) {
        CancelBtn.addActionListener(listener);
    }

    public JTable getTable(){
        return jTable1;
    }

    public void setTableModel(TableModel model){
        jTable1.setModel(model);
    }

    public int getSelectedRow(){
        return jTable1.getSelectedRow();
    }

    public int getRowCount(){
        return jTable1.getRowCount();
    }

    public DijkstraResult getResult(int i){
        return ((ResultTableModel)jTable1.getModel()).getRow(i);
    }

    public void blockDetailsBtn(boolean value) {
        DetailsBtn.setEnabled(value);
    }

    public void setInfo(String s){
        infoPath.setText(s);
    }

}
